// pages/image1/index.js
var t = getApp(),
  c = t.requirejs("api/index"),
  a = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    route: "appointment",
    menu: t.tabBar,
    menu_show: false,
    loaded: false,
    show: false,
    list: [],
    page: 1,
    info_list:[],
    info_show:false
  },

  onLoad: function (e) {

    if (e != null && e != undefined) {
      this.setData({
        tabbar_index: e.tabbar_index ? e.tabbar_index : -1
      });
    }

    a.setting();
    console.log(e)
    this.setData({
      menu: getApp().tabBar,
    })

    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: getApp().tabBar.IsDiDis ? getApp().tabBar.IsDiDis : false,
      })
    }

    this.getlist();

  },
  /**
     * 获取图片列表信息
     */
  getlist: function () {
    var that = this,
    e={},
      page = that.data.page;
    a.get('Market/UserBook', {
       user_id: t.getCache('userinfo').uid,
     page: page }, function (t) {
       if (t.code == 0) {
           t.info.length > 0 && (e.page = page + 1, e.list = that.data.list.concat(t.info), t.info.length < 10 && (e.loaded = true));
           t.info.length == 0 && (e.loaded = true);
           e.show = true;
         that.setData(e);
       } else {
         a.alert(t.msg, function () {
           return;
         })
    }
     })
  },
is_show:function(t){
  var index=a.pdata(t).index;
  var list=this.data.list;
    var ii=this.data.info_show;
    this.setData({
      info_show:ii?false:true
    })
    if(index!=-1){
      var info = list[index].param;
      info.forEach(function(t){
        console.log(t)
        if (t.key == 'pic_arr' && t.value){
          t.value = t.value.split(',');
        }
      })
      this.setData({
        info_list: info
      })
    }
},
  /**
    * 图片预览
    */
  previewImage: function (e) {
    var that = this,
      urls = [];
    that.data.list.forEach(function (t, k) {
      urls[k] = t.img_cover
    })
    wx.previewImage({
      current: a.pdata(e).url, // 当前显示图片的http链接
      urls: urls// 需要预览的图片http链接列表
    })
  },

  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    })
    this.getlist()
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getlist()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  //
  // }
})